#ifndef EVENT_HPP_
#define EVENT_HPP_

#include <map>
#include <string>
#include <sstream>
#include "kit/user/UserMap.hpp"
#include "kit/message/Message.hpp"

namespace KitEvent
{
	/**
	 * The class Event is a base class for events that might be handled
	 * by the application. A proper event implementation contains method execute
	 * that executes the even on the active user map that is provided as a parameter
	 * to methods that are operating on it. Every event has its string identifier that
	 * allows to identify if the event serves a given message. Events can be also verified
	 * if they are valid against some map of users. The valid method remains purely
	 * virtual as validity of an event might be considered in a different way, depending
	 * on the event that should be processed. The event aggregates a message that
	 * should be send to the user - obviously not all events needs it, but meaningful
	 * number of them do, so I have decided to keep in the base class.
	 */
	class Event
	{
	public:
		/**
		 * This constructor is called by default constructors of derived events to provide
		 * the event identifier. It is used in the event creator class.
		 */
		Event(std::string iIdentifier):_identifier(iIdentifier),_message(NULL){}
		/**
		 * This is a proper event constructor, that gets a message that it wrapps and the
		 * string identifier. This is constructor is used when a copy of an event that is
		 * handling a message is done by calling makeCopy method.
		 */
		Event(
				KitMessage::Message * iMessage,
				std::string iIdentifier):
					_message(iMessage),_identifier(iIdentifier){}
		/**
		 * Just a destructor. Nothing special.
		 */
        virtual ~Event();

        /**
         * The method checks if the given message is handled by the event object.
         *
         * \param iMessage message that should be handled.
         * \return true if the event handles iMessage, false otherwise.
         */
        virtual bool isMyEvent(KitMessage::Message * iMessage);
        /**
         * If the event handles a message this method should be used to create an object
         * handling the message in the proper way. It's purely virtual as the copy is
         * done on the base of particular implementation of the event.
         *
         * \param iMessage message that should be handled.
         * \return Event that will take care of processing iMessage
         */
        virtual Event * makeCopy(KitMessage::Message * iMessage)=0;
        /**
         * The method executed the event implementation knowing the user map. In example
         * it may send a message to users present in the user map.
         *
         * \param iUsers Users that are currently connected to the application.
         */
        virtual void execute(KitUser::UserMap * iUsers) = 0;
        /**
         * Checks if the event is valid. In example we may consider an event as valid if
         * the users related to the message it keeps are present in the system.
         *
         * \param iUsers Users that are currently connected to the application.
         */
        virtual bool isValid(KitUser::UserMap * iUsers) = 0;
        /**
         * Just a getter returning message serverd by the event.
         *
         * \return Message handled by the system.
         */
        KitMessage::Message * getMessage() const {return _message;}
    protected:
        // keeps message served by the event
        KitMessage::Message * _message;
        // unique event identifier
        const std::string _identifier;
	};
}

#endif /* EVENT_HPP_ */
